<template>
  <view class="container">
    <view class="header">
      <text class="header-title">{{ pageInfo.config.domain }}</text>
    </view>

    <view
      class="section"
      v-for="(item, index) in pageInfo.nav_list"
      :key="index"
    >
      <view class="section-title">
        <image
          :src="`${domain}${item.icon}`"
          mode="scaleToFill"
          class="title-icon"
        />
        <text>{{ item.category_name }}</text>
      </view>
      <view class="grid-container">
        <view
          class="grid-item"
          v-for="childItem in item.assNav"
          :key="childItem.id"
          @click="handleNavigateToWebUrl(childItem.url)"
        >
          <image :src="`${domain}${childItem.image}`" class="grid-icon" />
          <text class="grid-text">{{ childItem.nav_name }}</text>
        </view>
      </view>
    </view>
  </view>
</template>

<script setup lang="ts">
import { ref } from "vue";
import { fetchGetNavList } from "@/apis";
import { onLoad } from "@dcloudio/uni-app";

const pageInfo = ref();
const getNavList = async () => {
  const res = await fetchGetNavList();
  pageInfo.value = res.data;
};

const handleNavigateToWebUrl = (url: string) => {
  window.open(url);
};

// 自动获取当前完整的域名
const domain = window.location.origin;

onLoad(() => {
  getNavList();
});
</script>

<style>
.container {
  min-height: 100vh;
  background: url("https://img95.699pic.com/photo/40144/1887.gif_wh860.gif");
  background-repeat: no-repeat;
  background-position: center center;
  background-attachment: fixed;
  background-size: cover;
  padding: 20rpx 0;
}

.header {
  padding: 120rpx 0 40rpx;
  text-align: center;
}

.header-title {
  color: #ffffff;
  font-size: 60rpx;
  font-weight: bold;
}

.section {
  background-color: rgba(255, 255, 255, 0.9);
  margin: 30rpx 0;
  border-radius: 30rpx;
  padding: 40rpx;
}

.section-title {
  color: #ff0000;
  font-size: 32rpx;
  margin-bottom: 20rpx;
  box-sizing: border-box;
  padding: 0 50rpx;
  display: flex;
  align-items: center;
}

.title-icon {
  width: 40rpx;
  height: 40rpx;
  margin-right: 10rpx;
}

.grid-container {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 20rpx;
}

.grid-item {
  border-radius: 10rpx;
  padding: 20rpx;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.grid-icon {
  width: 80rpx;
  height: 80rpx;
  margin-bottom: 10rpx;
  border-radius: 10rpx;
}

.grid-text {
  color: #ff0000;
  font-size: 24rpx;
  text-align: center;
}
</style>
